package com.sunda.spmsuser.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sunda.spmsuser.entity.SpmsUserWhs;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户仓库关联关系表 Mapper 接口
 * </p>
 *
 * @author Wayne
 * @since 2021-01-25
 */
@Mapper
@Component
public interface SpmsUserWhsMapper extends BaseMapper<SpmsUserWhs> {

    @Select("SELECT suw.WERKS AS \"werks\",\n" +
            "  suw.WHS_LOCATION_CODE AS \"whsLocationCode\",\n" +
            "  whs.WHS_LOCATION_DESC AS \"whsLocationDesc\",\n" +
            "  whs.WHS_TYPE AS \"whsType\",\n" +
            "  whs.CONTACT AS \"contact\",\n" +
            "  whs.ADDRESS AS \"address\",\n" +
            "  whs.TELEPHONE AS \"telephone\",\n" +
            "  whs.CITY AS \"city\"\n" +
            "FROM SPMS_USER_WHS suw\n" +
            "  LEFT JOIN WHS whs ON suw.WERKS = whs.WERKS\n" +
            "                       AND suw.WHS_LOCATION_CODE = whs.WHS_LOCATION_CODE\n" +
            "  LEFT JOIN WERKS w ON suw.WERKS = w.WERKS WHERE suw.WORK_CODE = #{userId}")
    List<Map<String, Object>> getUserWhs(@Param("userId") String userId);
}
